# -*- coding: UTF-8 -*-   

'''问答类'''
from answer_search import AnswerSearcher
from question_classifier import QuestionClassifier
from question_parser import QuestionPaser


class ChatBotGraph:
    def __init__(self):
        self.classifier = QuestionClassifier()
        self.parser = QuestionPaser()
        self.searcher = AnswerSearcher()

    def chat_main(self, sent):
        answer = '没能理解您的问题，我数据量有限，仍在扩充中...'
        res_classify = self.classifier.classify(sent)
        
        #print('类别：',res_classify)
        res_sql = self.parser.parser_main(res_classify)
        #print('sql语句',res_sql)

        final_answers = self.searcher.search_main(res_sql)
        ##print(final_answers)
        if final_answers!=[]:
            print('答案如上您还可以继续咨询')
        else:
            print(answer)
           

            #return '\n'.join(final_answers)

if __name__ == '__main__':
    handler = ChatBotGraph()
    #测试-start
    # problems=["离散结构的知识单元","离散结构属于什么","数学基础的知识点","离散结构的先修课程","递归的掌握程度","递归的重要程度","李四的职称","李四老师多大","李四老师性别","张三的学号","张三同学的性别","张三同学多大","张三上大几","张三选修的课程","李四讲授的课程","张三什么专业的","李四管理的学生",]
    # problems=["离散结构的知识单元有哪些","离散结构的简介","离散结构的学时是多少","操作系统的先修课程有什么","离散结构的教学大纲","离散结构的知识点有哪些",
    #           "离散结构属于什么专业","功能组织掌握程度","功能组织重要程度","递归的前置知识点",
    #           "递归的后继知识点","程序设计基础的前置知识单元","程序设计基础的后继知识单元","操作系统的后继课程","操作系统的前置课程","建模基础涵盖哪些知识点",
    #           "建模基础属于什么课程","离散结构有多少知识单元？","离散结构有多少知识点？"]
    print("这是chatbot脚本\n")
    problems=["离散结构的知识点有哪些"]
    for id,problem in enumerate(problems):
        print("第{0}个问题是{1}：".format(id,problem))
        handler.chat_main(problem)
        print("\n")
    print("测试结束")
    # #测试-end
    # while 1:
    #     question = input('咨询:')
    #     handler.chat_main(question)



